<template>
  <section>
    <!--工具条-->
    <br/>
    <el-col :span="24" class="toolbar" style="padding-left: 10px">
      <el-form :inline="true" :model="filters">
        <el-form-item >
          <el-input v-model="filters.keyword" placeholder="摘要"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" v-on:click="getAdopt">查询</el-button>
        </el-form-item>
      </el-form>
    </el-col>

    <!--列表-->
    <el-table :data="adopt" highlight-current-row v-loading="listLoading" @selection-change="selsChange"
              style="width: 100%;">
      <el-table-column type="selection" width="55">
      </el-table-column>
      <el-table-column type="index" width="60">
      </el-table-column>
      <el-table-column prop="orderSn" label="订单编码" min-width sortable>
      </el-table-column>
      <el-table-column prop="digest" label="摘要" min-width sortable>
      </el-table-column>
      <el-table-column prop="price" label="价格" min-width sortable>
      </el-table-column>
      <el-table-column prop="lastPayTime" label="最后支付时间" min-width sortable>
      </el-table-column>
      <el-table-column prop="lastConfirmTime" label="最后确认时间" min-width sortable>
      </el-table-column>
      <el-table-column prop="state" label="状态" min-width sortable>
        <template scope="scope">
          <span style="color: #5daf34" v-if="scope.row.state === 0">待支付</span>
          <span style="color:red" v-else-if="scope.row.state === 1">待发货</span>
          <span style="color:yellow" v-else-if="scope.row.state === 2">待确认</span>
          <span style="color:green" v-else-if="scope.row.state === 3">已完成</span>
          <span style="color:gray" v-else-if="scope.row.state === -1">取消</span>
          <span style="color:dimgrey" v-else>未知</span>
        </template>
      </el-table-column>


      <el-table-column label="操作" min-width>
        <template scope="scope">
          <el-button size="small" @click="orderInfo(scope.$index, scope.row)">详情</el-button>
          <el-button type="danger" size="small" @click="handleDel(scope.$index, scope.row)">取消</el-button>
        </template>
      </el-table-column>
    </el-table>


    <br/>
    <el-col :span="24" class="toolbar">
      <el-button type="danger" @click="batchRemove" :disabled="this.sels.length===0" style="margin-left:10px">批量删除
      </el-button>
      <el-pagination
        background
        :current-page="page"
        :page-size="size"
        :total="total"
        :page-sizes="[5,10,15,20]"
        style="float:right;margin-right: 450px"
        layout="total, sizes, prev, pager, next, jumper"
        @current-change="currentChange"
        @size-change="sizeChange"
      ></el-pagination>
    </el-col>


    <!--详情界面-->
    <el-dialog title="订单详情" :visible.sync="adoptOrderInfoVisible" :close-on-click-modal="false">
      <el-form :model="adoptOrderInfo" label-width="120px" ref="adoptOrderInfo">
        <el-form-item label="摘要" prop="digest">
          <el-input readonly="readonly" v-model="adoptOrderInfo.digest" auto-complete="off"></el-input>
        </el-form-item>
        <el-form-item label="订单号" prop="orderSn">
          <el-input readonly="readonly" v-model="adoptOrderInfo.orderSn" auto-complete="off"></el-input>
        </el-form-item>
        <el-form-item label="价格" prop="price">
          <el-input readonly="readonly" v-model="adoptOrderInfo.price" auto-complete="off"></el-input>
        </el-form-item>
        <el-form-item label="状态" prop="state">
          <template scope="scope">
            <span style="color: green" v-if="adoptOrderInfo.state==0">待支付</span>
            <span style="color: red" v-else-if="adoptOrderInfo.state==1">已完成</span>
            <span style="color: gray" v-else>未知</span>
          </template>
        </el-form-item>
        <el-form-item label="最后确认时间" prop="lastConfirmTime">
          <el-input v-model="adoptOrderInfo.lastConfirmTime" auto-complete="off"></el-input>
        </el-form-item>

        <el-form-item label="宠物名称" prop="manager">
          <el-input readonly="readonly" v-model="adoptOrderInfo.pet.name" auto-complete="off"></el-input>
        </el-form-item>
        <el-form-item label="领养人" prop="parent">
          <el-input readonly="readonly" v-model="adoptOrderInfo.user.username" auto-complete="off"></el-input>
        </el-form-item>
        <el-form-item label="门店" prop="parent">
          <el-input readonly="readonly" v-model="adoptOrderInfo.shop.name" auto-complete="off"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click.native="adoptOrderInfoVisible = false">取消</el-button>
      </div>
    </el-dialog>

  </section>
</template>

<script>
import adoptOrder from '@/api/order/AdoptOrder'
//import NProgress from 'nprogress'

export default {
  data() {
    return {
      title: '',
      filters: {
        keyword: null,
        state:null
      },
      adopt: [],
      page: 1,
      total: 0,
      size: 5,
      listLoading: false,
      sels: [],//列表选中列

      adoptOrderInfoVisible: false,//新增界面是否显示
      adoptOrderInfo:{
        pet:{},
        shop:{},
        user:{},
      }
    }
  },
  methods: {

    currentChange(val) {
      this.page = val;
      this.getAdopt();
    },
    sizeChange(val) {
      this.size = val;
      this.getAdopt()
    },
    //获取列表
    getAdopt() {
      this.listLoading = true;//开启忙等框
      let temp = {
        currentPage:this.page,
        pageSize:this.size,
        keyword:this.filters.keyword,
        state:this.filters.state
      }
      adoptOrder.queryAdopt(temp)
        .then(response => {
          let data = response.data
          this.total = data.totals
          this.adopt = data.rows
          setTimeout(() => {
            this.listLoading = false
          }, 1.5 * 1000)//关闭忙等框
        })
    },

    //显示详情界面
    orderInfo: function (index, row) {
      this.title = "详情"
      this.adoptOrderInfoVisible = true;//显示编辑窗口
      adoptOrder.getAdoptById(row.id)
        .then(result=>{
          this.adoptOrderInfo = result.data.adopt;

        })
        .catch(result=>{
          this.adoptOrderInfoVisible = false;
        })

    },

    selsChange: function (sels) {
      this.sels = sels;
    },
    //批量删除
    batchRemove: function () {
      var ids = this.sels.map(item => item.id)
      this.$confirm('确认删除选中记录吗？', '提示', {
        type: 'warning'
      }).then(() => {
        this.listLoading = true;
        emp.deleteBatch(ids)
          .then(response => {
            return this.$message({
              showClose: true,
              message: '删除成功!',
              type: 'success'
            });
          })
          .then(response => {
            this.getAdopt()
          })
          .catch(error => {
            return this.$message({
              showClose: true,
              message: '删除失败!请稍后重试',
              type: 'error'
            })
          })
      }).catch(() => {

      });
    },

  },
  mounted() {
    this.getAdopt();
  }
}

</script>

<style scoped>


</style>
